package com.fastloan.mgt.product.question.service.impl;

import com.fastloan.common.BasicServiceImpl;
import com.fastloan.mgt.product.label.service.LabelService;
import com.fastloan.mgt.product.question.dao.QuestionMapper;
import com.fastloan.mgt.product.question.model.Question;
import com.fastloan.mgt.product.question.model.vo.QuestionVO;
import com.fastloan.mgt.product.question.service.QuestionService;
import com.fastloan.safe.core.util.ManagerKit;
import com.kawins.supers.tree.Bean2TreeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author admins
 * createTime 2017/12/27
 */
@Service
public class QuestionServiceImpl extends BasicServiceImpl<Question> implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;

    @Autowired
    private LabelService labelService;

    @Override
    public List<QuestionVO> queryQuestionTree() {
        Bean2TreeUtil<QuestionVO> treeUtil = new Bean2TreeUtil<>();
        List<QuestionVO> childNodesByParent = treeUtil.getChildNodesByParentId(questionMapper.queryByOrgId(ManagerKit.getOrgId()), 0);
        setQuestionVoInfo(childNodesByParent);
        return childNodesByParent;
    }

    private void setQuestionVoInfo(List<QuestionVO> questionVOList) {
        for (QuestionVO questionVO : questionVOList) {
            if (questionVO.getType().equals(0)) {
                questionVO.setIfQuestion(true);
            }else {
                questionVO.setIfQuestion(false);
            }
            if (!questionVO.getQuestionVOList().isEmpty()) {
                setQuestionVoInfo(questionVO.getQuestionVOList());
            }
        }
    }
}
